/*
 * Copyright 2008 Jens Meiss
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package mtt.menu;

import mtt.menu.events.ShowApplicationInfo;
import mtt.menu.events.ShowApplicationOptionEvent;
import mtt.menu.events.ShowCalendarEvent;
import mtt.menu.events.ShowMainMenuEvent;
import mtt.menu.mainmenu.MainMenuController;
import mtt.menu.mainmenu.MainMenuView;
import mtt.menu.mainmenu.events.ShowMainMenuViewEvent;
import hmvc.component.IComponent;
import hmvc.j2me.framework.events.IHmvcEvent;
import hmvc.j2me.framework.model.AHmvcModel;

/**
 * 
 * @author jens.meiss
 */
public class MenuModel extends AHmvcModel {
	
	IComponent componentMainMenu = null;

	public void init() {
		// TODO Auto-generated method stub

	}

	public void terminate() {
		// TODO Auto-generated method stub

	}

	public void handleEvent(IHmvcEvent event) {
		
		if (event instanceof ShowCalendarEvent) {
			
		} else if (event instanceof ShowMainMenuEvent) {
			showMainMenu();
		} else if (event instanceof ShowApplicationInfo) {
			
			
		} else if (event instanceof ShowApplicationOptionEvent) {
			
			
		}
		
	}

	private void showMainMenu() {
		
		if (componentMainMenu == null) {
			componentMainMenu = getController().getComponent().addChildComponent(new MainMenuController(), new MainMenuView());
		}
		
		componentMainMenu.fireEvent(new ShowMainMenuViewEvent(), false, true, false);
		
	}

	public void registerEvents() {
		getHmvcController().register(ShowApplicationInfo.class, this);
		getHmvcController().register(ShowApplicationOptionEvent.class, this);
		getHmvcController().register(ShowCalendarEvent.class, this);
		getHmvcController().register(ShowMainMenuEvent.class, this);
	}

}
